<template>
	<view class="content reg-page">
		<view class="input-group">
			<view class="input-column border-bottom-1px">
				<text class="title">
					<text class="yzb yzb-bitian" />
					真实姓名
				</text>
				<view class="input-item">
					<m-input type="text" v-model="data.realname" placeholder="请输入真实姓名" :maxLength="30"></m-input>
				</view>
			</view>
			<view class="input-column border-bottom-1px">
				<text class="title">
					<text class="yzb yzb-bitian" />
					手机号码
				</text>
				<view class="input-item">
					<m-input type="text" v-model="data.phone" placeholder="请输入用于登录的手机号" :maxLength="20"></m-input>
				</view>
			</view>
			<view class="input-column border-bottom-1px">
				<text class="title">
					<text class="yzb yzb-bitian" />
					验证码
				</text>
				<view class="input-item flex">
					<m-input type="number" maxlength="6" placeholder="请输入验证码" v-model="data.code" 
						style="width: 70%;" />
					<view class="codeText" v-if="coding == false" @click="getCode()">获取验证码</view>
					<view class="authTime" v-else>{{ auth_time }}秒</view>
				</view>
			</view>
			<view class="input-column border-bottom-1px">
				<text class="title">
					<text class="yzb yzb-bitian" />
					担任职位
				</text>
				<view class="input-item"><input class="padding-10" placeholder="请输入职位,如总经理/招聘人员等" v-model="data.postName" /></view>
			</view>
		</view>
		<view class="btn-row row">
			<button type="primary" class="btn-save width-90"  @tap="save">保存</button>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
import mInput from '@/components/m-input/m-input.vue';
import mCell from '@/components/m-cell/m-cell.vue';
import graceChecker from '@/common/graceChecker.js';
import formRuleConfig from '@/config/formRule.config.js';
export default {
	components: {
		mInput,
		mCell,
	},
	computed: {
		...mapState(['userInfo']),
	},
	data() {
		return {
			id:'',
			data:{
				companyId:'',
				code:''
			},
			coding: false,
			auth_time: 60,
		};
	},
	
	onLoad() {
		
	},
	
	methods: {
		
		
		/**
		 * 获取验证码
		 */
		async getCode() {
			// 判断手机号格式是否正确
			var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
			if (!myreg.test(this.data.phone)) {
				uni.showToast({
					icon: 'none',
					title: '请输入正确的手机号码'
				});
				return false;
			}
			//设置倒计时秒
			this.auth_time = 60;
			this.coding = true;
			var auth_timetimer = setInterval(() => {
				this.auth_time--;
				if (this.auth_time < 0) {
					this.coding = false;
					clearInterval(auth_timetimer);
				}
			}, 1000);
			//获取验证码
			let params = { 
				phone: this.data.phone,
				smsmode:1,//短信模板方式  0 .登录模板、1.注册模板、2.忘记密码模板
			};
			let data = await this.$apis.getVerifyCode(params,{isRes: true});
			console.log('getVerCode===', data);
			if (data) {
				uni.showToast({title: data.message});
			}else{
				uni.showToast({title: '获取失败,请重试',icon:'none'});
			}
		},

		async save() {
			this.data.companyId=this.userInfo.companyId;
			let checkRes = graceChecker.check(this.data, formRuleConfig.recruiterRule);
			if (!checkRes) {
				uni.showToast({
					title: graceChecker.error,
					icon: 'none'
				});
				return;
			}
			let res = await this.$apis.addCompanyUser(this.data);
			if (res) {
				uni.navigateBack({
					delta: 1
				});
			}
		},
	}
};
</script>

<style lang="scss" scoped>
.yzb-bitian {
	color: $font-color-red;
}

.input-group {
	border-radius: 10upx;
	margin-top: 10upx;
	overflow: hidden;
	padding-bottom: 120upx;
}

.input-row {
	display: flex;
	flex-direction: row;
	position: relative;
	background: #fff;
	justify-content: space-between;
	align-items: center;
	padding: 15upx 10upx;
}

.input-row .title {
	width: 25%;
	padding: 20upx 0;
	padding-left: 20upx;
	line-height: 50upx;
	color: $font-color-333;
}

.border-bottom-1px {
	// border-bottom: 1upx solid $border-color-light;
	position: relative;
	&::after {
		position: absolute;
		z-index: 1;
		right: 0;
		bottom: 0;
		left: 20upx;
		height: 1upx;
		content: '';
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		background-color: #e2e2e2;
	}
}

.header {
	display: flex;
	flex-direction: column;
	.tip {
		font-size: $uni-font-size-sm;
		color: $font-color-666;
		margin-left: 20upx;
	}
}

.head-img {
	margin-right: 15upx;
	image {
		width: 160upx;
		height: 160upx;
		border-radius: 50%;
	}
}

radio-group {
	margin-right: 10upx;
}

.radio {
	margin-left: 20upx;
}

.input-column {
	display: flex;
	flex-direction: column;
	background-color: $bgcolor_white;
	padding: 30upx 20upx 10upx 20upx;

	.title {
		margin-left: 10upx;
		color: $font-color-333;
	}

	.input-item {
		// display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}
	
	.flex{
		display: flex;
	}
	
	.codeText{
		color: $main-color;
	}

	.picker {
		padding: 30upx 0 20upx 0;
		margin-left: 10upx;
		position: relative;
		picker {
			font-size: $uni-font-size-lg;
			width: 100%;
			position: absolute;
		}
	}
	.yzb-next {
		float: right;
		color: $font-color-999;
	}
}

.content {
	background: $bgcolor_white;
}

.btn-row {
	position: fixed;
	z-index: 999;
	bottom: 0upx;
	padding: 20upx;
	background-color: #ffffff;
	width: 100%;
	box-sizing: border-box;
	display: flex;
	flex-direction: row;
	align-items: center;
	box-sizing: border-box;
	.btn-delete {
		background-color: $bg-grey;
		height: 80upx;
		line-height: 80upx;
		margin-right: 20upx;
		font-size: $font-size-34;
		color: $font-color-333;
		width: 30%;
	}

	.btn-save {
		background-color: $main-color;
		height: 80upx;
		line-height: 80upx;
		font-size: $font-size-34;
	}
	.width-55 {
		width: 55%;
	}

	.width-90 {
		width: 90%;
	}
}
</style>
